$(function () {
    var $dialogModel = $('#dialogNew');
    var frm = new IIFoxLoader(
        {
            cls: "#frmTest",
            url: "iifoxHandler/answer",
            //mapRelation: {
            //    default1: "#default1"
            //},
            click: {
                '#btnSave1': function (element) {
                    var that = this;
                    var options = $.extend(true, {}, this.options,
                        { data: this.dataEntity.get() });

                    swal({

                        title: "确认提交",
                        type: "warning",
                        showCancelButton: true,

                        confirmButtonText: "确认",
                        confirmButtonClass: "btn-danger ml-2",
                        cancelButtonText: "取消",
                        cancelButtonClass: 'btn-secondary',

                    }).then(function (result) {
                        if (result.dismiss === 'cancel') {
                            toastr.info("", "已取消");
                            return;
                        }
                        setTimeout(function () {
                            $.bc({
                                url: options.url,
                                method: "put",
                                query: { fq: "btnSave1" },
                                data: options.data,
                                callback: function (result) {
                                    if (result == false) {
                                        swal({
                                            html: true,
                                            title: "提交失败",
                                            text: "提交失败,请重试！",
                                            type: "error",
                                            showCancelButton: false,
                                            cancelButtonClass: 'btn-secondary',
                                            confirmButtonText: "确认",
                                            confirmButtonClass: "btn-danger ml-2",
                                            cancelButtonText: "取消"

                                        });
                                    }
                                    else {
                                        that.Load(result);
                                        toastr.success("", "保存成功");
                                        //swal({
                                        //    html: true,
                                        //    title: "提交成功",
                                        //    text: "提交成功",
                                        //    type: "info",
                                        //    showCancelButton: false,
                                        //    cancelButtonClass: 'btn-secondary',
                                        //    confirmButtonText: "确认",
                                        //    confirmButtonClass: "btn-danger ml-2",
                                        //    cancelButtonText: "取消"
                                        //});
                                    }
                                }
                            });
                        }, 100);
                    }
                    );
                }
                ,
                '#btnSave2': function (element) {

                    $dialogModel.modal('show');

                }
            }

        }
    ).Init();


    var c_url = "iifoxHandler/answer";
    var $table = $('table');

    $table.lgbTable({
        url: c_url,
        if_blank: true,
        PostUrl: "iifox/answerdetail/",
        dataBinder: {
            map: {
                //AE_ID: "#AE_ID"
            },
            callback: function (data) {

                if (data && data.oper === 'confirm') {
                    $dialogModel.modal('hide');
                    $("#IP222").val(data.data["AE_ID"]);
                }

            }
        },
        smartTable: {

            idSelectField: "AE_ID,AE_ID,AE_ID",
            showExport: false,
            showColumns: false,                  //是否显示所有的列
            showRefresh: false,                  //是否显示刷新按钮
            showToggle: false,                   //是否显示详细视图和列表视图的切换按钮
            idField: "AE_ID",
            sortName: "AE_ID",
            sortOrder: "asc",
            queryParams: function (params) {
                return $.extend(params, {
                    IP: $("#txt_IP").val(),
                    Phone: $('#txt_Phone').val()
                });
            },           //传递参数（*）
            columns: [
                { title: "AE_ID", field: "AE_ID", sortable: true },
                { title: "IP", field: "IP", sortable: true },
                { title: "M_ID", field: "M_ID", sortable: true },
                { title: "A_ID", field: "A_ID", sortable: true },
                { title: "IsFinished", field: "IsFinished", sortable: true },
                { title: "AnswerDate", field: "AnswerDate", sortable: true },
                { title: "Email", field: "Email", sortable: true },
                { title: "Phone", field: "Phone", sortable: true },
                { title: "vFlag", field: "vFlag", sortable: true },
                { title: "vUser", field: "vUser", sortable: true },
                { title: "SurvryCode", field: "SurvryCode", sortable: true },
                { title: "nFile", field: "nFile", sortable: true },
                { title: "vFlag2", field: "vFlag2", sortable: true },
                { title: "CusName", field: "CusName", sortable: true }
            ],
            editButtons: {
                events: {
                    'click': function (e, value, row, index) {
                        $table.bootstrapTable('uncheckAll');
                        $table.bootstrapTable('check', index);
                    }
                },
                formatter: function (value, row, index) {
                    var $this = this.clone();
                    if (row.IsReset === 0) {
                        $this.find('button.reset').remove();
                    }
                    return $this.html();
                }
            }
        }
    });
});


$('.nav-tabs').on('click', 'a', function (e) {
    e.preventDefault();
    if ($(this).hasClass('flex-fill')) return;

    $('.nav-tabs').find('.nav-link').removeClass('active');
    $(this).addClass('active');
    var that = this;
    $('.detail iframe').removeClass('active').filter(function (index, ele) {
        if ($(ele).attr('src') === $(that).attr('href')) $(ele).addClass('active');
    });
})
